package com.retailshop.shopuser.common;

import java.text.SimpleDateFormat;
import java.util.Calendar;
public class CheckCode {

    private static final String KEY = "xlsphone2019";

    public static boolean checkCode(String phone,String code,String codeTime,String requestHash){


        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MINUTE, 0);
        String currentTime = sf.format(c.getTime());

       String hash = MD5Util.getMD5Code(KEY + "@" + codeTime + "@" + code);

        if(OtherConstants.RegexpPhone(phone)){//验证手机号

            if(codeTime.compareTo(currentTime) > 0){//比较code时间

                if(requestHash.equalsIgnoreCase(hash)){//比较code值
                    return true;
                }

            }


        }

      return false;

    }


}
